package com.hu.generator;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class MpGenerator {

    public static void main(String[] args) {
       AutoGenerator autoGenerator = new AutoGenerator();
        //选择freemarker引擎，默认veloctiy
        autoGenerator.setTemplateEngine(new FreemarkerTemplateEngine());

        //1.全局配置
        GlobalConfig globalConfig = new GlobalConfig();

                globalConfig.setAuthor("HU")
                .setOutputDir("D://java项目/SSMjoio/src/main/java")//设置生成的路径
                .setActiveRecord(true)//设置开启AR模式
                .setEnableCache(false)//设置不开启二级缓存
                .setFileOverride(true)//设置可以覆盖同名文件
                .setServiceName("%sService")//设置生成service接口的名字的首字母是否为I
                .setBaseResultMap(true) //设置自动在mybatis.xml生成resultMap
                .setBaseColumnList(true); //设置自动生成通用查询结果列

        //2.数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();

        dataSourceConfig.setDbType(DbType.MYSQL) //设置需要访问的数据库类型
                .setDriverName("com.mysql.jdbc.Driver")
                .setUrl("jdbc:mysql://192.168.0.207:3306/ku3?serverTimezone=GMT%2B8")
                .setUsername("sun")
                .setPassword("sun");

        //3.策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setCapitalMode(true)//全局大写命名
                //.setDbColumnUnderline(true)//指定表名字段名是否启用下划线
                .setNaming(NamingStrategy.underline_to_camel)//数据库表映射到实体的命名策略
                //.setTablePrefix("tab_")  //设置表名前缀
        /*.setInclude("Student")*/; //指定生成的表

        //4.包名策略配置
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("com.hu")
                .setXml("mapper")
                .setServiceImpl("service")
                .setController("controller")
               /* .setMapper("mapper")
                .setService("service")
                .setController("controller")
                .setEntity("entity")
                .setXml("mapper")*/;

        //5.整合配合
        autoGenerator.setGlobalConfig(globalConfig)
                .setDataSource(dataSourceConfig)
                .setStrategy(strategyConfig)
                .setPackageInfo(packageConfig);

        //6.执行
        autoGenerator.execute();


    }
}
